<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>
    /* 
      1 手指放在屏幕上
      2 手指在屏幕上移动
      3 手指离开屏幕
    */
    function swipe (ele, handler) {
      var 
        flag = false,
        x = 0,
        y = 0
      ele.addEventListener('touchstart', function (e) {
        flag = false
        x = e.changedTouches[0].clientX
        y = e.changedTouches[0].clientY
      })

      ele.addEventListener('touchmove', function (e) {
        var 
          moveX = e.changedTouches[0].clientX - x,
          moveY = e.changedTouches[0].clientY - y,
          move = Math.sqrt(Math.pow(moveX, 2) + Math.pow(moveY, 2))
        if (move >= 6) {
          flag = true
        }
        
      })

      ele.addEventListener('touchend', function (e) {
        if (flag) {
          handler.call(this, e)
        }
      })
    }
  
    swipe(document, function () {
      console.log('滑动')
    })
  
  </script>
</body>
</html>